
package com.assistant.core.modules.sys.adapter.web.menu;

import com.assistant.core.modules.sys.app.menu.cmd.MenuInsertCmd;
import com.assistant.core.modules.sys.app.menu.cmd.MenuUpdateCmd;
import com.assistant.core.modules.sys.domain.menu.Menu;
import com.assistant.core.modules.sys.app.menu.MenuService;
import com.assistant.util.MessageBodyWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping(value = "/sys")
public class MenuController {

    @Autowired
    private MenuService menuService;

    @GetMapping(value = "/menu/{id}")
    public MessageBodyWrapper<Menu> get(@PathVariable("id") Long id) {
        return MessageBodyWrapper.success(menuService.get(id));
    }

    @GetMapping(value = "/menus")
    public MessageBodyWrapper<List<Menu>> list() {
        return MessageBodyWrapper.success(menuService.list());
    }

    @PostMapping(value = "/menu")
    public MessageBodyWrapper<Object> insert(@RequestBody MenuInsertCmd cmd) {
        menuService.insert(cmd);
        return MessageBodyWrapper.success();
    }

    @PutMapping(value = "/menu/{id}")
    public MessageBodyWrapper<Object> update(@PathVariable("id") Long id, @RequestBody MenuUpdateCmd cmd) {
        cmd.setId(id);
        menuService.update(cmd);
        return MessageBodyWrapper.success();
    }

    @DeleteMapping(value = "/menu/{id}")
    public MessageBodyWrapper<Object> delete(@PathVariable("id") Long id) {
        menuService.delete(id);
        return MessageBodyWrapper.success();
    }
}

